﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace IPad_The_Text_Editor_By_Siddharth_Singh
{
    

    public partial class Form1 : Form
    {
        public static string filedata;
   
        public static string path;
        public Point mouse_offset;
        public int b;
        public int a;

        public bool n;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            mouse_offset = new Point(-e.X, -e.Y);
        }
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point mousePos = Control.MousePosition;
                mousePos.Offset(mouse_offset.X, mouse_offset.Y);
                Location = mousePos;
            }
        }
        private void toolStripButton2_Click(object sender, EventArgs e)
        {

            if (n == true)
            {
                this.WindowState = FormWindowState.Maximized;
                a = a++;
                n = false;
            }

            else if (n == false)
            {
                this.WindowState = FormWindowState.Normal;
                n = true;
            }


        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            openFileDialog1.ShowDialog();
            path = openFileDialog1.FileName;
            richTextBox1.Visible = true;
            richTextBox1.Enabled = true;
            StreamReader reader;
            reader = new StreamReader(path) ;
            
            filedata = reader.ReadToEnd();
            richTextBox1.Text = filedata;
            reader.Close();

           
         

         
        }

        private void button2_Click(object sender, EventArgs e)
        {
           
            filedata = richTextBox1.Text;
            
           
            File.WriteAllText(path, filedata);
            richTextBox1.Enabled = false;
            richTextBox1.Visible = false;
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            filedata = filedata.Replace(textBox2.Text, textBox3.Text);
            richTextBox1.Text = filedata;
        }
    }
}
